removido
Trade Com X Storage
Por Sofft, 05 de set. de 2012 em Scripts
info
Grupo: Herói
Registrado: 20/05/10
Posts: 3.4k
Reputação: +1.5k
Gênero: Masculino

Editado Julho 28 por Vodkart
info
Grupo: Artesão
Registrado: 03/12/11
Posts: 137
Reputação: +5
Char no Tibia: Surionz

@Vodkart, items agrupáveis estão comprando ao quadrado.
Ex: compro 2 worms, recebo 4,
compro 3 recebo 9.
info
Grupo: Herói
Registrado: 20/05/10
Posts: 3.4k
Reputação: +1.5k
Gênero: Masculino

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser,msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid,string.lower(msg)
local trade = {
{name="platinum amulet", id=2171, buy=0, sell=2500},
{name="ring of the sky", id=2123, buy=0, sell=3000},
{name="ruby necklace", id=2133, buy=0, sell=2000},
{name="scarab amulet", id=2135, buy=0, sell=200},
{name="silver brooch", id=2134, buy=0, sell=150},
{name="terra amulet", id=7887, buy=0, sell=1500},
{name="doll", id=2110, buy=0, sell=200},
{name="light shovel", id=5710, buy=0, sell=300},
{name="pirate voodo doll", id=5810, buy=0, sell=50},
{name="voodo doll", id=3955, buy=0, sell=400}
}
local items = {}
for _, item in ipairs(trade) do
items[item.id] = {item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name}
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].buyPrice ~= 0 then
doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
if isItemStackable(items[item].item_id) then
doPlayerAddItem(cid, items[item].item_id, amount)
else
for i = 1, amount do
doPlayerAddItem(cid, items[item].item_id, 1)
end
end
end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if items[item].sellPrice ~= 0 then
doPlayerAddMoney(cid, items[item].sellPrice * amount)
doPlayerRemoveItem(cid, items[item].item_id, amount)
end
end
if msgcontains(msg, 'trade') and getPlayerStorageValue(cid, 784745) > 0 then
openShopWindow(cid, trade, onBuy, onSell)
else
selfSay("Não vendo nada para você!", cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Editado Setembro 14 por Vodkart
info
Grupo: Artesão
Registrado: 03/12/11
Posts: 137
Reputação: +5
Char no Tibia: Surionz

@Vodkart agora não está verificando o cap do player, vai comprando e caindo no chão, e não funciona "buy with backpacks", não estou reclamando, desse jeito está otimo, só estou notificando, ok?
info
Grupo: Lorde
Registrado: 22/07/12
Posts: 2.2k
Reputação: +453
Char no Tibia: Kissy

Duvida Sanada
Reportado
Para Um Superior





info
Grupo: Artesão
Registrado: 03/12/11
Posts: 137
Reputação: +5
Char no Tibia: Surionz
Distro: TFS 9.63
Olá Xtibianos,
Pedido: Quero Criar um NPC que dê TRADE apenas com players que terminaram X Quest.
Tentativa: No meu Ot 8.60 funciona perfeitamente esse modelo abaixo:
if (getPlayerStorageValue(cid, storage) < 16 and msgcontains(msg, "trade")) then npcHandler:say("You are not able to negotiate with me, help me every day and then you can do it.", cid) elseif (getPlayerStorageValue(cid, storage) >= 16 and msgcontains(msg, "trade")) then local items = { {name="platinum amulet", id=2171, buy=0, sell=2500}, {name="ring of the sky", id=2123, buy=0, sell=3000}, {name="ruby necklace", id=2133, buy=0, sell=2000}, {name="scarab amulet", id=2135, buy=0, sell=200}, {name="silver brooch", id=2134, buy=0, sell=150}, {name="terra amulet", id=7887, buy=0, sell=1500}, {name="doll", id=2110, buy=0, sell=200}, {name="light shovel", id=5710, buy=0, sell=300}, {name="pirate voodo doll", id=5810, buy=0, sell=50}, {name="voodo doll", id=3955, buy=0, sell=400} } openShopWindow(cid, items, function(cid, itemid, subType, amount, ignoreCap, inBackpacks) customCallbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks, items) end, function(cid, itemid, subType, amount, ignoreCap, inBackpacks) customCallbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks, items) end ) npcHandler:say("Of course, just browse through my wares.", cid) endErro: Quando eu uso esse script no 9.63 não é possível comprar items que não são agrupáveis, e o seguinte erro é exibido no console:
O que eu realmente quero: Ficaria muito grato se alguém conseguisse "consertar" essa função para mim, se não der por favor postem outras soluções.
Material Necessário:
function customCallbackOnBuy:
function customCallbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks, shopWindow) local shopItem, npcHandler = nil, NpcHandler for _, item in ipairs(shopWindow) do if not item.subType then item.subType = (isItemFluidContainer(item.id) == TRUE or isItemStackable(item.id) == TRUE) and 0 or 1 end if(item.id == itemid and (item.subType == subType)) then shopItem = item break end end if(shopItem == nil) then error("[shopModule.onBuy]", "Item not found on shopItems list") return false end if(shopItem.buy < 0) then error("[shopModule.onSell]", "Attempt to purchase an item which is only sellable") return false end local backpack, totalCost = 1988, amount * shopItem.buy if(inBackpacks) then totalCost = isItemStackable(itemid) == TRUE and totalCost + 20 or totalCost + (math.max(1, math.floor(amount / getContainerCapById(backpack))) * 20) end if(getPlayerMoney(cid) < totalCost) then doPlayerSendCancel(cid, npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_NEEDMONEY), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = totalCost, [TAG_ITEMNAME] = shopItem.name})) return false end local subType = shopItem.subType or isItemFluidContainer(itemid) == TRUE and 0 or 1 local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack) if(a < amount) then local msgId = MESSAGE_NEEDMORESPACE if(a == 0) then msgId = MESSAGE_NEEDSPACE end doPlayerSendCancel(cid, npcHandler:parseMessage(npcHandler:getMessage(msgId), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = totalCost, [TAG_ITEMNAME] = shopItem.name, [TAG_ITEMCOUNT] = a})) if(a > 0) then doPlayerRemoveMoney(cid, ((a * shopItem.buy) + (b * 20))) return true end return false end doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_BOUGHT), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = totalCost, [TAG_ITEMNAME] = shopItem.name})) doPlayerRemoveMoney(cid, totalCost) return true end